#include "pagelightsetting.h"
#include "ui_pagelightsetting.h"

PageLightSetting::PageLightSetting(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::PageLightSetting)
{
    ui->setupUi(this);
    setAutoFillBackground(true);  //设置自动填充
    QPalette palette = BKGCLR;
    setPalette(palette);

    connect(ui->ButtonAdd, SIGNAL(released()), this, SLOT(AddButtonClicked()));
    connect(ui->ButtonSub, SIGNAL(released()), this, SLOT(SubButtonClicked()));
    connect(ui->ButtonAuto, SIGNAL(released()), this, SLOT(AutoButtonClicked()));
    connect(ui->ButtonManul, SIGNAL(released()), this, SLOT(manulButtonClicked()));
}

PageLightSetting::~PageLightSetting()
{
    delete ui;
}

void PageLightSetting::AddButtonClicked()
{
    if(ui->LightBar->value() < 450)
    {
        setLight(ui->LightBar->value()+50);
    }
}

void PageLightSetting::SubButtonClicked()
{
    if(ui->LightBar->value() > 50)
    {
        setLight(ui->LightBar->value()-50);
    }
}

void PageLightSetting::AutoButtonClicked()
{

    ui->ButtonAuto->setEnabled(false);
    setLight(0);
    ui->ButtonManul->setChecked(false);
    ui->ButtonManul->setEnabled(true);
    ui->ButtonAdd->setEnabled(false);
    ui->ButtonSub->setEnabled(false);
}

void PageLightSetting::manulButtonClicked()
{

    ui->ButtonManul->setEnabled(false);
    setLight(100);
    ui->ButtonAuto->setChecked(false);
    ui->ButtonAuto->setEnabled(true);
    ui->ButtonAdd->setEnabled(true);
    ui->ButtonSub->setEnabled(true);
}

void PageLightSetting::setLight(int val)
{
    if(val>=50 && val<=450)
    {
        ui->LightBar->setValue(val);
        emit SetBackLightValue(val);
    }
}
